// pages/myOrder/myOrder.js
const app = getApp()
var api = require('../../../utils/api.js')
var util = require('../../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    limit: 10,
    total_page: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getOrderLIst();
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  // 获取订单列表
  getOrderLIst: function () {
    var params = new Object()
    var that = this;
    params.page = this.data.page;
    params.limit = this.data.limit;

    api.POST({
      params: params,
      url: app.globalData.base_url + 'aftersale/getList',
      success: function (res) {
        wx.hideLoading();
        if (util.isEmpty(res.data.code)) {
          var paging = res.data.data.paging;
          var totalPage = paging.total_page;
          var orderList = res.data.data.list;

          if (that.data.page == 1) {
            var itemData = orderList;
          } else {
            var itemData = that.data.product.concat(orderList)
          }

          that.setData({
            total_page: totalPage,
            product: itemData
          })
        }
      },
      fail: function (fail) {
        util.showError("网络错误，请检查网络");
      }
    })
  },

  //加载更多
  loadMore: function () {
    if (this.data.page >= this.data.total_page) {
      return;
    }
    wx.showLoading({
      title: '加载中',
    })
    this.setData({
      page: this.data.page + 1
    });
    this.getOrderLIst();
  },

  //刷新页面
  resetData: function () {
    var that = this
    that.setData({
      page: 1,
      hasMore: true
    });
  },
  //页面下拉刷新
  onPullDownRefresh: function () {
    var that = this;

    setTimeout(function () {
      that.resetData()
    }, 1000)
  },

  //页面上拉触底
  onReachBottom: function (e) {
    this.loadMore();
  },
  detailsCol:function(e){
    var id = e.currentTarget.dataset.id;
    var status = e.currentTarget.dataset.status;

    if(status==1){
      wx.navigateTo({
        url: '/center/pages/refundSecond/refundSecond?id=' +id
      })
    } else if (status == 10 || status == 11) {
        wx.navigateTo({
           url: '/center/pages/refundCheck/refundCheck?id=' + id
        })
     }else{
      wx.navigateTo({
        url: '/center/pages/refundSuccessful/refundSuccessful?id=' + id
      })
    }
    
  }
})